package db;

import javax.microedition.rms.RecordComparator;

public class FoodComparator implements RecordComparator {

    public int compare(byte[] rec1, byte[] rec2) {
        // omptimized for speed, just reads first three char of name
        // assumes all foods has at least 3 characters, less than that
        // is condidered as equal
        if (rec1[39] < 3 || rec2[39] < 3) {
            return RecordComparator.EQUIVALENT;
        }
        long f1 = (rec1[40] << 16) | (rec1[41] << 8) | (rec1[42]);
        long f2 = (rec2[40] << 16) | (rec2[41] << 8) | (rec2[42]);
        long c = f1 - f2;
        
        if (c > 0) {
            return RecordComparator.FOLLOWS;
        }
        if (c < 0) {
            return RecordComparator.PRECEDES;
        }
        return RecordComparator.EQUIVALENT;

    }
}
